/*
 * @Author: zhouwei wei.zhou@flip.fun
 * @Date: 2024-04-08 23:16:40
 * @LastEditors: zhouwei wei.zhou@flip.fun
 * @LastEditTime: 2024-04-08 23:27:10
 * @FilePath: /50/手撕系列/Object_assign.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
function assign(target, ...args) {
	if (target == null) {
		throw new TypeError('Cannot convert undefined or null to object')
	}
	let ret = Object(target)
	args.forEach(function (obj) {
		if (obj != null) {
			for (let key in obj) {
				if (obj.hasOwnProperty(key)) {
					ret[key] = obj[key]
				}
			}
		}
	})
	return ret
}

// 测试代码
// 验证Object构造函数参数为对象时,直接返回的源对象
const obj = {}
const newObj = new Object(obj)
console.log(obj === newObj)
console.log(Object.assign(1, {}))
